package com.wtp.wallpaper.aspect.processor;

import com.wtp.wallpaper.pojo.entity.UserUpload;
import com.wtp.wallpaper.pojo.vo.*;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

// 3. 创建处理器工厂
public class ProcessorFactory {
    private static final Map<Class<?>, UrlProcessor<?>> processors = new HashMap<>();
    
    static {
        registerProcessor(PictureVO.class, new PictureProcessor());
        registerProcessor(ClassifyVO.class, new ClassifyProcessor());
        registerProcessor(BannerPicVO.class, new BannerPicProcessor());
        registerProcessor(PicurlVO.class, new PicurlProcessor());
        registerProcessor(UserUploadVO.class, new UserUploadProcessor());
    }

    private static <T> void registerProcessor(Class<T> type, UrlProcessor<T> processor) {
        processors.put(type, processor);
    }

    @SuppressWarnings("unchecked")
    public static <T> Optional<UrlProcessor<T>> getProcessor(Class<T> type) {

        return Optional.ofNullable((UrlProcessor<T>) processors.get(type));
    }
}